package bean.factorybean;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @Author com.alibaba.lizhen
 * @Date 2021/3/30 11:46 上午
 * @Version 1.0
 * @Description
 */
@Component("personFactoryBean")
public class PersonFactoryBean implements FactoryBean<Person> {
	/**
	 * 初始化Str
	 */
	private String initStr = "10, init from PersonFactoryBean";

	@Override
	public Person getObject() throws Exception {
		System.out.println("-------FactoryBean的getObject方法调用");
		//这里我需要获取对应参数
		Objects.requireNonNull(initStr);
		String[] split = initStr.split(",");
		Person p = new Person();
		p.setAge(Integer.parseInt(split[0]));
		p.setName(split[1]);
		//这里可能需要还要有其他复杂事情需要处理
		return p;
	}

	@Override
	public Class<?> getObjectType() {
		return Person.class;
	}

	public String getInitStr() {
		return initStr;
	}

	public void setInitStr(String initStr) {
		this.initStr = initStr;
	}


	@Override
	public boolean isSingleton() {
		return false;
	}
}
